<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title></title>
    <link rel="stylesheet" href="__COMPONENT__/pear/css/pear.css" />
    <link rel="stylesheet" href="__COMPONENT__/layui/css/layui.css" />
</head>
<body class="pear-container">
<form class="layui-form layui-form-pane" method="post">
    <div class="layui-tab-item layui-show layui-col-md6 layui-col-md-offset2">
        <div class="layui-form-item">
            <label class="layui-form-label">标签标题</label>
            <div class="layui-input-block">
                <input type="text" name="tag_name" required  lay-verify="required" placeholder="请输入标题" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">标签描述</label>
            <div class="layui-input-block">
                <textarea name="tag_content" placeholder="请输入标签相关介绍" class="layui-textarea"></textarea>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-upload-drag" id="image_upload">
                <i class="layui-icon"></i>
                <p>点击或拖拽上传，标签封面</p>
                <div class="layui-hide" id="uploadDemoView">
                    <img src="" alt="上传成功后渲染" style="max-width: 196px;margin-top: 15px">
                    <input type="hidden" name="tag_image_cover" id="tag_image_cover" autocomplete="off">
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">标签状态</label>
            <div class="layui-input-block">
                <input type="checkbox" checked="" name="status" lay-skin="switch" lay-filter="switchStatus" title="开关">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">标签浏览数</label>
            <div class="layui-input-block">
                <input type="number" name="tag_views" placeholder="请输入浏览数" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">SEO关键字</label>
            <div class="layui-input-block">
                <textarea name="seo_keywords" placeholder="请输入SEO关键词，请使用逗号隔开" class="layui-textarea"></textarea>
            </div>
        </div>
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">SEO描述</label>
            <div class="layui-input-block">
                <textarea name="seo_description" placeholder="请输入SEO描述，内容请不要超过100字" class="layui-textarea"></textarea>
            </div>
        </div>
        <div class="layui-form-item layui-form-text">
            <div class="layui-input-block">
                <button type="submit" id="save" class="layui-btn" lay-submit="" lay-filter="save">立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </div>
</form>
<script src="__COMPONENT__/layui/layui.js"></script>
<script src="__COMPONENT__/pear/pear.js"></script>
<script>
    layui.use(['treeSelect','form','jquery','notice','upload'], function () {
        var $ = layui.jquery;
        var form = layui.form;
        var notice = layui.notice;
        var upload = layui.upload;

        //拖拽上传
        upload.render({
            elem: '#image_upload'
            , url: '/admin.php/upload'
            ,accept: 'image'
            ,size: 4 * 1024
            , done: function (res) {
                console.log(res.data)
                layui.$('#uploadDemoView').removeClass('layui-hide').find('img').attr('src', res.data);
                layui.$("#tag_image_cover").val(res.data);
            }
        });

        //提交数据
        form.on('submit(save)', function(data){
            if (data.field.status=='on'){
                data.field.status = 1;
            }else{
                data.field.status = 0;
            }

            $.ajax({
                type:'post',
                url: "/admin.php/tags/add",
                data:data.field,
                success:function(result){
                    if(result.code==1){
                        var index = parent.layer.getFrameIndex(window.name);
                        parent.layer.close(index);
                    }else{
                        notice.error(result.msg)
                    }
                }
            })
            return false;
        });
    });
</script>
</body>
</html>
